package com.kuaiditu.assistant.api.xz_api;

import com.kuaiditu.assistant.api.xz_api.xz_encode.xz_http.FormBodyBuilderFactory;

import java.util.Map;

/**
 * Created by Eenie on 2017/9/14.
 * Email: eeniework@gmail.com
 * Des:
 */

public class YTBaseRequest {

    private int cmd;
    private Object data;
    private Map extMap;
    private String uuid;


    public int getCmd() {
        return cmd;
    }

    public void setCmd(int cmd) {
        this.cmd = cmd;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Map getExtMap() {
        return extMap;
    }

    public void setExtMap(Map extMap) {
        this.extMap = extMap;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }



    public Map<String, String> build() {
        return FormBodyBuilderFactory.create(this.cmd, this.data, this.extMap, this.uuid);
    }


    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer();
        for (Map.Entry<String, String> entry : build().entrySet()) {
            sb.append(entry + "=" + entry.getValue() + "&");
        }
        if (sb.length() > 0) {
            return sb.substring(0, sb.length() - 1);
        }
        return sb.toString();
    }

    public static YTBaseRequest DEFAULT(Integer cmd, Object data, Map<String, String> extMap, String uid) {
        YTBaseRequest request = new YTBaseRequest();
        request.setCmd(cmd);
        request.setData(data);
        request.setExtMap(extMap);
        request.setUuid(uid);
        return request;
    }
}
